﻿/*文件注释
 * ===============================================================================
 * 说明：
 * 作者：zengyy
 * 版本：v1.0
 * 创建日期：2013-12-07 19:10:39
 * 完成日期： 
 * 修改纪录：  
 * ===============================================================================
 */
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SRF.Admin
{
    /// <summary>
    ///  数据规则项 Service
    /// </summary>
    public class DataRuleItemService
    {
        readonly Data.DBHelperBase dbhelper = Data.DBHelperFactory.GetDBHelper();

        /// <summary>
        /// 获取
        /// </summary>
        /// <param name="id">id</param>
        /// <returns>返回</returns>
        public Models.DataRuleItem Get(string id)
        {
            return dbhelper.GetQuery("admin.dataruleitem.get").SetParameter(new { Id = id }).UniqueResult<Models.DataRuleItem>();
        }
        /// <summary>
        /// 获取列表
        /// </summary>
        /// <returns>返回列表</returns>
        public IList<Models.DataRuleItem> List(string dataRuleId = null)
        {
            return dbhelper.GetQuery("admin.dataruleitem.list").SetParameter(new { DataRuleId = dataRuleId }).List<Models.DataRuleItem>();
        }
        /// <summary>
        /// 保存
        /// </summary>
        /// <param name="post"></param>
        /// <returns>返回Id</returns>
        public string Save(Models.DataRuleItem dataRuleItem)
        {
            if (string.IsNullOrEmpty(dataRuleItem.Id))
            {
                dataRuleItem.Id = Guid.NewGuid().ToString();
                dbhelper.GetQuery("admin.dataruleitem.insert").SetParameter(dataRuleItem).Execute();
            }
            else
            {
                dbhelper.GetQuery("admin.dataruleitem.update").SetParameter(dataRuleItem).Execute();
            }

            return dataRuleItem.Id;
        }
        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="id">Id</param>
        public void Delete(string id)
        {
            dbhelper.GetQuery("admin.dataruleitem.delete").SetParameter("Id", id).Execute();
        }

        public IList<string> GetDataRuleItemsByRole(string roleId)
        {
            return dbhelper.GetQuery("admin.dataruleitem.getbyrole").SetParameter("roleId", roleId).List<string>();
        }
    }
}

